﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MotorcycleStore.Repository;
using MotorcycleStore.DomainModel;

namespace MotorcycleStoreData.EF
{
	public class ManufacturerRepository : IManufacturerRepository
	{
		MotorcycleStoreContext context;

		public ManufacturerRepository(string connectionString)
		{
			context = new MotorcycleStoreContext(connectionString);
		}

		public IQueryable<Manufacturer> Manufacturers
		{
			get { return context.Manufacturers; }
		}

		public void Add(Manufacturer manufacturer)
		{
			context.Manufacturers.AddObject(manufacturer);
		}

		public void Delete(int manufacturerId)
		{
			var entity = context.Manufacturers.Single(m => m.Id == manufacturerId);
			context.DeleteObject(entity);
		}

		public void Save()
		{
			context.SaveChanges();
		}
	}
}
